import { GlobalHooks } from '../../core/hooks';
import { IPSAppDataEntity, PSDEGridFieldColumnImpl } from '../../exports';
import { IPSModelObject } from '../../ipsmodel-object';
import { IGetModel4ModelHookTap } from '../interface';

/**
 * 表格属性列
 *
 * @author chitanda
 * @date 2022-03-07 19:03:13
 * @export
 * @class PSDEGridFieldColumn
 */
export class PSDEGridFieldColumn implements IGetModel4ModelHookTap {
  constructor() {
    GlobalHooks.getModel4.tap('PSDEGridFieldColumn', this.getModel4);
  }

  getModel4(modelObj: IPSModelObject, cls: string, obj: IModel, tag?: string): IPSModelObject | undefined {
    if (modelObj.cls === 'PSDEGridFieldColumnImpl' && obj.modelref === true) {
      const model = modelObj as PSDEGridFieldColumnImpl;
      if (cls === 'app.dataentity.IPSAppDEField') {
        const entity = model.getParentPSModelObject('app.dataentity.IPSAppDataEntity') as IPSAppDataEntity;
        if (entity) {
          return entity.findPSAppDEField(obj) || undefined;
        }
      }
    }
    return undefined;
  }
}
